package cn.tpshion.task.task;

import cn.tpshion.task.common.MsgAction;
import cn.tpshion.task.data.MsgData;
import cn.tpshion.task.data.TaskData;
import com.alibaba.fastjson.JSON;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MsgTaskHandler extends MsgHandler{

    private final TaskManager taskManager;

    public MsgTaskHandler(TaskManager taskManager) {
        this.taskManager = taskManager;
    }

    @Override
    protected MsgAction action() {
        return MsgAction.TASK;
    }

    @Override
    public void handler(ChannelHandlerContext ctx, MsgData msgData) {
        TaskData taskData = JSON.parseObject(msgData.getData(), TaskData.class);
        taskManager.execute(taskData, ctx);
    }
}
